﻿@namespace BootstrapBlazor.Components
@typeparam TItem
@inherits BootstrapComponentBase

<div @attributes="@AdditionalAttributes" class="@ClassName">
    @if (HeaderTemplate != null)
    {
        <div class="listview-header">
            @HeaderTemplate
        </div>
    }
    <div class="listview-body">
        @if (BodyTemplate != null && Items != null)
        {
            if (GroupName == null)
            {
                foreach (var item in Items)
                {
                    <div class="listview-item" @onclick="@(e => OnClick(item))">
                        @BodyTemplate.Invoke(item)
                    </div>
                }
            }
            else
            {
                foreach (var key in Items.GroupBy(GroupName).OrderBy(k => k.Key))
                {
                    <div class="listview-item-group">@key.Key</div>
                    @foreach (var item in key)
                    {
                        <div class="listview-item" @onclick="@(e => OnClick(item))">
                            @BodyTemplate.Invoke(item)
                        </div>
                    }
                }
            }
        }
    </div>
    @if (FooterTemplate != null || Pageable)
    {
        <div class="listview-footer">
            @if (Pageable)
            {
                <Pagination PageItemsSource="@PageItemsSource" PageItems="@PageItems" TotalCount="@TotalCount" PageIndex="@PageIndex" OnPageClick="@OnPageClick" OnPageItemsChanged="@OnPageItemsChanged"></Pagination>
            }
            else
            {
                @FooterTemplate
            }
        </div>
    }
</div>
